package com.duan.goods.controller;

import com.duan.entity.Result;
import com.duan.goods.pojo.Classify;
import com.duan.goods.service.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类表
 */
@RestController
@RequestMapping("/Classify")
@CrossOrigin
public class ClassifyController {
    @Autowired
    private ClassifyService classifyService;

    /**
     * 查询全部分类
     * @param
     * @return
     */
    @GetMapping("/selectAll")
    @PreAuthorize("hasAnyAuthority('b')")
    public Result<List<Classify>> selectAll(){
        return Result.ok("查询成功",classifyService.selectAll());
    }

    /**
     * 新增分类
     * @param classify
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Classify classify){
        classifyService.insert(classify);
        return Result.ok("新增成功");
    }

    /**
     * 删除分类
     * @param ids
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam String ids){
        classifyService.delete(ids);
        return Result.ok("删除成功");
    }

    /**
     * 修改分类
     * @param classify
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Classify classify){
        classifyService.update(classify);
        return Result.ok("修改成功");
    }


}
